package com.huiquan.management.controller;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.huiquan.analysis.domain.User;
import com.huiquan.framework.base.ReturnData;
import com.huiquan.management.service.GradeService;

@Controller
public class GradeController {

	@Autowired
	private GradeService gradeService;

	/**
	 * 获取标注分词句子等级
	 * 
	 * @param req
	 * @param resp
	 * @return
	 * @throws IOException
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/management/grade_sentence_display.htm")
	public ModelAndView sentenceisplay(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		String tabid = req.getParameter("tabid");
		// 维护页面参数到session
		Map<String, Object> pageParam;
		if (tabid != null && !tabid.isEmpty()) {
			pageParam = new HashMap<>();
			pageParam.put("tabid", tabid);

			req.getSession().setAttribute("pageParam", pageParam);
		} else {
			pageParam = (Map<String, Object>) req.getSession().getAttribute("pageParam");
		}

		return gradeService.sentenceDisplay();
	}

	@ResponseBody
	@RequestMapping(value = "/management/grade_udpate_param.do")
	public ReturnData updateParam(HttpServletRequest req, HttpServletResponse resp) throws Exception {
		String idStr = req.getParameter("id");
		String paramTypeStr = req.getParameter("paramType");
		String gradeStr = req.getParameter("grade");
		String param = req.getParameter("param");
		User user = (User) req.getSession().getAttribute("user");

		long gradeId = Long.parseLong(idStr);
		int paramType = Integer.parseInt(paramTypeStr);
		int grade = Integer.parseInt(gradeStr);

		return gradeService.updateParam(gradeId, paramType, grade, param, user);
	}

}
